clear all; clc;

data = load('CompileHyperShockData.mat');


runIndex = 1; 



times = data.Time(runIndex); times = times{1};

rates = data.GrowthRate(runIndex); rates = rates{1};

%[200 400 400 400 400 400 600 800 800 1000 1200 2000]

plot(times, rates)

dlmwrite('rate-vs-time-400mM.txt',transpose([times; rates]))

l = EffectiveLengthNoSTD(times, rates);

%l = l/(l(60));

plot(times, rates)

dlmwrite('length-vs-time-400mM.csv',transpose([times; l]))

%% 
indices = [1 200 21 27; 2 400 20 24; 3 400 60 64; 7 600 19 24; 8 800 19 24; 10 1000 20 25; 11 1200 20 25; 12 2000 20 26]; 

ind = 4;

runIndex = indices(ind, 1); 

rates = data.GrowthRate(runIndex); rates = rates{1};

% (mean(rates(indices(ind, 4):end))- mean(rates(1:indices(ind, 3)))) / mean(rates(1:indices(ind, 3)))

s400 = (1.55 - 1.54)/1.55;
s600 = (1.689 - 1.627)/1.689;
s800 = (1.659 - 1.58)/1.659;
s1000 = (1.824 - 1.602)/1.824;
s1200 = (1.561 - 1.437)/1.561;
s2000 = (1.542 - 1.45)/1.542;

molars = [400, 600, 800, 1000, 1200, 2000];
strains = [s400, s600, s800, s1000, s1200, s2000];

% plot(molars, strains)

% ta200 = 21; tb200 = 27; 
% ta400 = 20; tb400 = 24;
% ta600 = 19; tb600 = 24;
% ta800 = 19; tb800 = 24;
% ta1000 = 20; tb1000 = 25;
% ta1200 = 20; tb1200 = 24;
% ta2000 = 20; tb2000 = 26;



%%
%plot(times, l)

%EffectiveLength(times, rates, std(rates))

% t= times; v = rates; varargin = [];%std(rates);

% dt=diff(t);
% meanV=(v(1:end-1)+v(2:end))/2;
% 
% l=zeros(size(v));
% l0=3;
% l(1)=l0;
% 
% for i=2:length(l)
%     l(i)=l(i-1)+l(i-1)*meanV(i-1)*dt(i-1);
% end
% 
% if length(varargin)==1
%     varargout=cell(1,2);
%     lmax=zeros(size(v));
%     lmin=zeros(size(v));
%     vstd=varargin{1};
%     
%     lmax(1)=l(1);
%     lmin(1)=l(1);
%     for i=2:length(l)
%         lmax(i)=l(i-1)+l(i-1)*(meanV(i-1)+vstd(i-1))*dt(i-1);
%         lmin(i)=l(i-1)+l(i-1)*(meanV(i-1)-vstd(i-1))*dt(i-1);
%     end   
%     varargout{1}=lmax;
%     varargout{2}=lmin;
%     
% end